using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using SapaFinance.Domain.Model;

namespace SapaFinance.Domain.EntityFramework
{
    public class BankConfiguration : EntityTypeConfiguration<Bank>
    {
        public BankConfiguration()
        {
            ToTable(typeof(Bank).Name.ToLower());
            HasKey(x => x.UID);
            Property(x => x.UID).HasColumnName("id").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            Property(x => x.Bin).HasColumnName("bin").IsRequired();
            Property(x => x.Name).HasColumnName("name").IsRequired();
            Property(x => x.Swift).HasColumnName("swift");
            Property(x => x.Address).HasColumnName("address");
            Property(x => x.CorrespondentAccount).HasColumnName("correspondentaccount").IsRequired();
            Property(x => x.IsHidden).HasColumnName("ishidden").IsRequired();
            Property(x => x.City).HasColumnName("city").IsRequired();
            HasRequired(p => p.CreatedBy).WithMany().Map(m => m.MapKey("createdbyid")).WillCascadeOnDelete(false);
            HasRequired(p => p.ChangedBy).WithMany().Map(m => m.MapKey("changedbyid")).WillCascadeOnDelete(false);
        }
    }
}